package com.zxl.diy.weather.location;

import android.content.Context;

/**
 * Created by Administrator on 2016/11/5.
 */
public class LocationHelper extends BaseLocationHelper {

    private static final int FLAG_GPS = 1;

    private static final int FLAG_NET = 2;

    private static final int FLAG_CELL = 3;

    private int mFlag;

    private CellLocationHelper mCellLocationHelper;

    private AndroidLocationHelper mGpsLocationHelper;

    private AndroidLocationHelper mNetLocationHelper;

    public LocationHelper(Context mContext, OnLocationStatusListener mOnLocationStatusListener) {
        super(mContext, mOnLocationStatusListener);
        mCellLocationHelper = new CellLocationHelper(mContext, mOnLocationStatusListener);
        mGpsLocationHelper = AndroidLocationHelper.createGpsLocationHelper(mContext, mOnLocationStatusListener);
        mNetLocationHelper = AndroidLocationHelper.createNetLocationHelper(mContext, mOnLocationStatusListener);
    }

    @Override
    public void startLocation() {
        super.startLocation();
        mFlag = FLAG_CELL;
        mCellLocationHelper.startLocation();
    }

    @Override
    public void onLocationFailed(int status) {
        if (mFlag == FLAG_GPS) {
            mFlag = FLAG_NET;
            mNetLocationHelper.startLocation();
        } else if (mFlag == FLAG_NET) {
            super.onLocationFailed(status);
        }  else if (mFlag == FLAG_CELL) {
            mFlag = FLAG_GPS;
            mGpsLocationHelper.startLocation();
        }
    }
}
